using System.Collections.Generic;
using UnityEngine;

public class SkinsExporterPanel : MonoBehaviour
{
	public UIPanel panel;

	public UIGrid buttonsGrid;

	public SkinForExportButton buttonExample;

	public List<SkinForExportButton> panelButtons = new List<SkinForExportButton>();

	public SkinForExportButton selectedButton;

	public string selected = string.Empty;

	public List<SkinForExportButton> buttonsPull;

	public virtual void Awake()
	{
		if ((bool)buttonExample)
		{
			buttonExample.gameObject.SetActive(false);
		}
	}

	public virtual void InitButtons()
	{
		ClearButtons();
	}

	public virtual void OnEnable()
	{
	}

	public virtual void OnDisble()
	{
	}

	public virtual void SetButton(string id, int index = -1)
	{
		if (!buttonExample)
		{
			BCWDebug.LogError("No button Example!");
			return;
		}
		SkinForExportButton skinForExportButton = GetButtonFromPull();
		if (skinForExportButton == null)
		{
			skinForExportButton = InstantiateButton();
		}
		if (index > -1)
		{
			skinForExportButton.gameObject.name = index.ToString();
		}
		skinForExportButton.gameObject.SetActive(true);
		skinForExportButton.Init(id, this);
		panelButtons.Add(skinForExportButton);
	}

	public virtual SkinForExportButton GetButtonFromPull()
	{
		if (buttonsPull.Count < 1)
		{
			return null;
		}
		SkinForExportButton result = buttonsPull[0];
		buttonsPull.RemoveAt(0);
		return result;
	}

	public virtual SkinForExportButton InstantiateButton()
	{
		SkinForExportButton skinForExportButton = Object.Instantiate(buttonExample);
		skinForExportButton.transform.SetParent(buttonsGrid.transform);
		skinForExportButton.transform.localScale = Vector3.one;
		return skinForExportButton;
	}

	public virtual void ClearButtons()
	{
		for (int i = 0; i < panelButtons.Count; i++)
		{
			panelButtons[i].UnloadProductTexture();
			panelButtons[i].gameObject.SetActive(false);
			buttonsPull.Add(panelButtons[i]);
		}
		panelButtons.Clear();
	}

	public virtual void Select(string item, bool selectDefault = true)
	{
		selected = item;
	}

	public virtual void Unselect()
	{
		selected = string.Empty;
		selectedButton = null;
	}
}
